package data_structure;

public class leetcode_0129 {
    public int sumNumbers(TreeNode root) {
        int[] result=new int[1];
        dp(result,root.val,root);
        return result[0];
    }
    public void dp(int[] result,int num,TreeNode node){
        if(node.left==null&&node.right==null){
            result[0]+=num;
            return;
        }
        if(node.left!=null){
            dp(result,10*num+node.left.val,node.left);
        }
        if(node.right!=null){
            dp(result,10*num+node.right.val,node.right);
        }
    }
}
